/* VersusView.cpp
 * The battle gameplay view
 *
 * Last Modified: 16.01.2014
 * Author: Guilherme S.G.
 *
 * TODO:
 */
#include "VersusView.h"
#include "Game.h"

VersusView::VersusView() : View()
{
    ResourceManager *resources = controller->getResources();
    ALLEGRO_BITMAP *bg;
    int selectedNinja, randomEnemy, numberOfNinjas;
    
    al_resize_display(controller->getDisplay(), 1280, 350);
    al_set_window_position(controller->getDisplay(), 0, 450);
    
    bg = resources->loadImage("assets/backgrounds/versus-f1.png", "bg-f1");
    background.push_back(bg);
    bg = resources->loadImage("assets/backgrounds/versus-f2.png", "bg-f2");
    background.push_back(bg);
    bg = resources->loadImage("assets/backgrounds/versus-f3.png", "bg-f3");
    background.push_back(bg);
    bg = resources->loadImage("assets/backgrounds/versus-f4.png", "bg-f4");
    background.push_back(bg);
    
    selectedNinja = controller->getPlayerSelection();
    player = controller->getNinja(selectedNinja);
    player->setPosition(100, 270);
    player->setLookingDirection(0);
    
    numberOfNinjas = controller->getNumberNinjas();
    randomEnemy = selectedNinja;
    
    while(randomEnemy == selectedNinja)
        randomEnemy = rand()%numberOfNinjas;
    
    enemy = controller->getNinja(randomEnemy);
    enemy->setPosition(1160, 270);
    enemy->setLookingDirection(1);
}

VersusView::~VersusView()
{
    
}

void VersusView::handleEvents(ALLEGRO_EVENT *event)
{
    if(event->type == ALLEGRO_EVENT_KEY_UP)
    {
        switch (event->keyboard.keycode)
        {
            case ALLEGRO_KEY_ESCAPE:
                controller->setNextView(MENU);
                break;
        }
    }
}

void VersusView::update()
{
    
}

void VersusView::render()
{
    //Animated background
    std::vector<ALLEGRO_BITMAP*>::iterator iter;
    for(iter = background.begin(); iter != background.end(); iter++)
    {
        al_draw_bitmap(*iter, 0, 0, 0);
    }
    
    //Ninja's portraits and HP
    
    
    //Ninjas
    player->render();
    enemy->render();
}



